home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / gnu / gnu_tile_forth.lha / tst / byte-sieve.tst < prev    next >
Text File  |  1992-05-19  |  1KB  |  43 lines

  1. .( Loading Byte Magazine Sieve benchmark...) cr
  2.  
  3. \ This is the "standard" sieve benchmark as published in Byte Magazine.
  4. \ The algorithm is wrong in the sense that it gives an incorrect count
  5. \ of the number of primes.  That doesn't affect it's usefulness as a
  6. \ benchmark.
  7. \
  8. \ This benchmark tends to be relatively insensitive to the efficiency
  9. \ of "nesting" (calling a colon definition), since it is implemented
  10. \ almost entirely with very low level words, which are code words in
  11. \ most Forth implementations.  This is reasonably fair, however, since
  12. \ studies have shown that in many Forth programs, code words get
  13. \ executed on the order of 8 times more frequently than colon
  14. \ definitions.
  15.  
  16. decimal
  17.  
  18. 8192 constant size ( -- int)
  19. create flags ( -- addr) size allot
  20.  
  21. : do-prime ( -- )
  22.   flags size 1 fill
  23.   0 size 0 do
  24.     flags i + c@
  25.     if i dup + 3 + dup i +
  26.       begin
  27.     dup size <
  28.       while
  29.     0 over flags + c!
  30.     over +
  31.       repeat
  32.       2drop 1+
  33.     then
  34.   loop
  35.   1899 = not abort" prime: wrong result"
  36. ;
  37.  
  38. : byte-sieve ( -- )
  39.   10 0 do do-prime loop
  40. ;
  41.  
  42. forth only
  43.